<!--
Copyright 2011 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->


<!--
Run this script on a different origin than unit_tests/index.html
will be run on. Paste the public key that is output into
line 9 of unit_tests/index.html.

This file sets up for a test of same-origin policies:
the unit_tests/index.html shouldn't be able to use this
origin's public key for vTPM operations.
-->
<html>
<head>
</head>

<script src="../src/add_event_listener.js" type="text/javascript"></script>
<script src="../src/vtpm_const.js" type="text/javascript"></script>
<script src="../src/vtpm_user.js" type="text/javascript"></script>

<script type="text/javascript">

function go() {
  var now = new Date(); // for use in generating policies
  var later = new Date(now);
  later.setFullYear(now.getFullYear()+1);

  window.crypto.generatePolicy(now, later, vtpmKeyPolicy.usage.dataEncipherment | vtpmKeyPolicy.usage.digitalSignature,
    onPolicyGen);
}

function onPolicyGen(policy) {
  window.crypto.generateKeyPair(policy, onKeyPairGen);
}

function onKeyPairGen(pk) {
  document.getElementById("status").innerHTML = "Paste the following public key into unit_tests/index.html:<br />" + pk;
}

</script>

<body onload="go()">
<span id="status"></span>
</body>
</html>
